package com.hongkuncheng.cms.model;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.io.Serializable;

@Entity
public class FormData implements Serializable {
    protected int id;
    protected Date subtime;
    protected String ipaddress;
    protected String disposeUser;
    protected String result;
    protected String evaluate;
    protected Form form;
    protected Member member;
    protected FormDataAtisfaction formDataAtisfaction;
    protected List<FormDataValue> formDataValues;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "subtime", nullable = false)
    public Date getSubtime() {
        return subtime;
    }

    public void setSubtime(Date subtime) {
        this.subtime = subtime;
    }

    @Basic
    @Column(name = "ipaddress", nullable = false, length = 255)
    public String getIpaddress() {
        return ipaddress;
    }

    public void setIpaddress(String ipaddress) {
        this.ipaddress = ipaddress;
    }

    @Basic
    @Column(name = "dispose_user", nullable = true, length = 255)
    public String getDisposeUser() {
        return disposeUser;
    }

    public void setDisposeUser(String disposeUser) {
        this.disposeUser = disposeUser == null || disposeUser.isEmpty() ? null : disposeUser;
    }

    @Basic
    @Column(name = "result", nullable = true, length = -1)
    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result == null || result.isEmpty() ? null : result;
    }

    @Basic
    @Column(name = "evaluate", nullable = true, length = -1)
    public String getEvaluate() {
        return evaluate;
    }

    public void setEvaluate(String evaluate) {
        this.evaluate = evaluate == null || evaluate.isEmpty() ? null : evaluate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        FormData formData = (FormData) o;
        return id == formData.id &&
                Objects.equals(subtime, formData.subtime) &&
                Objects.equals(ipaddress, formData.ipaddress) &&
                Objects.equals(disposeUser, formData.disposeUser) &&
                Objects.equals(result, formData.result) &&
                Objects.equals(evaluate, formData.evaluate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, subtime, ipaddress, disposeUser, result, evaluate);
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "form_id", referencedColumnName = "id", nullable = false)
    public Form getForm() {
        return form;
    }

    public void setForm(Form form) {
        this.form = form;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "member_id", referencedColumnName = "id", nullable = false)
    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "atisfaction_id", referencedColumnName = "id")
    public FormDataAtisfaction getFormDataAtisfaction() {
        return formDataAtisfaction;
    }

    public void setFormDataAtisfaction(FormDataAtisfaction formDataAtisfaction) {
        this.formDataAtisfaction = formDataAtisfaction;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "formData")
    public List<FormDataValue> getFormDataValues() {
        return formDataValues;
    }

    public void setFormDataValues(List<FormDataValue> formDataValues) {
        this.formDataValues = formDataValues;
    }
}
